@echo off
chcp 65001

set /p setPan=请输入存放项目的盘符:
set /p setProject=请输入你的项目名:

set Pan=%setPan%:

set Path1=%Pan%\C\Makefile
set Path2=%Path1%\%setProject%

::echo %Path2%

if not exist %Pan% (
	echo '%Pan%'不存在
) else (
	echo '%Pan%'存在
)

Timeout /t 2

::%Pan%存在
::start "" %Path1%
if not exist %Path1% (
	echo %Path1%不存在
	mkdir %Path1%
) else (
	echo %Path1%存在
)

timeout /t 2

if not exist %Path2% (
	echo %Path2%不存在
	mkdir %Path2%

	if not exist %Path2%\Inc (
		mkdir %Path2%\Inc
		echo 创建了%Path2%\Inc

		::main.h
		echo=>%Path2%\Inc\main.h
		echo #ifndef __MAIN_H__ >> %Path2%\Inc\main.h
		echo #define __MAIN_H__ >> %Path2%\Inc\main.h
		echo #include ^<stdio.h^>>>%Path2%\Inc\main.h
		echo #include ^<math.h^>>> %Path2%\Inc\main.h
		echo #include ^<string.h^>>>%Path2%\Inc\main.h
		echo #endif				>> %Path2%\Inc\main.h

		::main.c
		echo=>%Path2%\main.c
		echo #include "Inc/main.h" >> %Path2%\main.c
		echo #include "Inc/add.h"  >> %Path2%\main.c
		echo int main(void^){		>> %Path2%\main.c
		echo 	printf("Hello World,^%d\n",add(2,4^)^);	>> %Path2%\main.c
		echo 	return 0;			>> %Path2%\main.c
		echo }						>> %Path2%\main.c

		::add.h
		echo=>%Path2%\Inc\add.h
		echo #ifndef __ADD_H__ >> %Path2%\Inc\add.h
		echo #define __ADD_H__ >> %Path2%\Inc\add.h
		echo #include ^<stdio.h^>>>%Path2%\Inc\add.h
		echo #include ^<math.h^>>> %Path2%\Inc\add.h
		echo #include ^<string.h^>>>%Path2%\Inc\add.h
		echo int add(int,int^);	>> %Path2%\Inc\add.h
		echo #endif				>> %Path2%\Inc\add.h

		::add.c
		echo=>%Path2%\add.c
		echo #include "Inc/add.h" >> %Path2%\add.c
		echo int add(int a, int b^){		>> %Path2%\add.c
		echo 	return a + b;			>> %Path2%\add.c
		echo }						>> %Path2%\add.c

		::Makefile
		echo=>%Path2%\Makefile
		echo OBJ1 = add.exe     >> %Path2%\Makefile
		echo main:$(OBJ1^)				>> %Path2%\Makefile
		echo 	gcc $(OBJ1^) main.c -o main >> %Path2%\Makefile
		echo $(OBJ1^):add.c	>> %Path2%\Makefile
		echo 	gcc add.c -nostartfiles -o $@ >> %Path2%\Makefile
		echo clean:			>>  %Path2%\Makefile
		echo 	del *.exe		>> %Path2%\Makefile
		echo p:					>> %Path2%\Makefile
		echo 	@.\main.exe		>> %Path2%\Makefile

	) else (
		echo %Path2%\Inc文件已存在
	)

	start "" %Path2%
) else (
	if not exist %Path2%\Inc (
		mkdir %Path2%\Inc
		echo 创建了%Path2%\Inc

		::main.h
		echo=>%Path2%\Inc\main.h
		echo #ifndef __MAIN_H__ >> %Path2%\Inc\main.h
		echo #define __MAIN_H__ >> %Path2%\Inc\main.h
		echo #include ^<stdio.h^>>>%Path2%\Inc\main.h
		echo #include ^<math.h^>>> %Path2%\Inc\main.h
		echo #include ^<string.h^>>>%Path2%\Inc\main.h
		echo #endif				>> %Path2%\Inc\main.h

		::main.c
		echo=>%Path2%\main.c
		echo #include "Inc/main.h" >> %Path2%\main.c
		echo #include "Inc/add.h"  >> %Path2%\main.c
		echo int main(void^){		>> %Path2%\main.c
		echo 	printf("Hello World,^%d\n",add(2,4^)^);	>> %Path2%\main.c
		echo 	return 0;			>> %Path2%\main.c
		echo }						>> %Path2%\main.c

		::add.h
		echo=>%Path2%\Inc\add.h
		echo #ifndef __ADD_H__ >> %Path2%\Inc\add.h
		echo #define __ADD_H__ >> %Path2%\Inc\add.h
		echo #include ^<stdio.h^>>>%Path2%\Inc\add.h
		echo #include ^<math.h^>>> %Path2%\Inc\add.h
		echo #include ^<string.h^>>>%Path2%\Inc\add.h
		echo int add(int,int^);	>> %Path2%\Inc\add.h
		echo #endif				>> %Path2%\Inc\add.h

		::add.c
		echo=>%Path2%\add.c
		echo #include "Inc/add.h" >> %Path2%\add.c
		echo int add(int a, int b^){		>> %Path2%\add.c
		echo 	return a + b;			>> %Path2%\add.c
		echo }						>> %Path2%\add.c

		::Makefile
		echo=>%Path2%\Makefile
		echo OBJ1 = add.exe     >> %Path2%\Makefile
		echo main:$(OBJ1^)				>> %Path2%\Makefile
		echo 	gcc $(OBJ1^) main.c -o main >> %Path2%\Makefile
		echo $(OBJ1^):add.c	>> %Path2%\Makefile
		echo 	gcc add.c -nostartfiles -o $@ >> %Path2%\Makefile 
		echo clean:				>> %Path2%\Makefile
		echo 	del *.exe		>> %Path2%\Makefile
		echo p:					>> %Path2%\Makefile
		echo 	@.\main.exe		>> %Path2%\Makefile

	) else (
		echo %Path2%\Inc文件已存在
	)
	start "" %Path2%
)

::timeout /T 2

::pause